package com.wn.controller;

import com.common.entity.PageParam;
import com.common.entity.Plan;
import com.common.entity.Programme;
import com.common.entity.Rsp;
import com.github.pagehelper.PageInfo;
import com.wn.service.PlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class PlanController {

    @Autowired
    private PlanService planService;

    /**
     * @ClassName
     * @Description : 分页查询计划信息
     * @param: pageParam
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("searchSomeByPagePlan")
    @ApiOperation("分页查询计划信息")
    public Rsp searchSomeByPagePlan(@RequestBody PageParam<Plan> plan,
                                    @RequestHeader("token") String token){
        PageInfo<Plan> pg = planService.searchSomeByPage(plan);
        return Rsp.success(pg);
    }

    /**
     * @ClassName
     * @Description :根据id查询计划信息
     * @param : id
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("getOneByIdPlan/{id}")
    public Rsp getOneByIdPlan(@PathVariable("id") String id,
                              @RequestHeader("token") String token){
        Plan oneById = planService.getOneById(id);
        return Rsp.success(oneById);
    }

    /**
     * @ClassName
     * @Description : addOne添加计划
     * @param:
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("addOnePlan")
    @ApiOperation("添加计划")
    public Rsp addOnePlan(@RequestBody Plan plan,
                          @RequestHeader("token") String token){
        System.out.println(plan.toString());
        return planService.addOne(plan);
    }

    /**
     * @ClassName
     * @Description : update修改计划
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("updatePlan")
    public Rsp updatePlan(@RequestBody Plan plan,
                          @RequestHeader("token") String token){
        return planService.update(plan);
    }


    /**
     * @ClassName
     * @Description : deleteLogical逻辑删除计划
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("deleteLogicalPlan")
    public Rsp deleteLogicalPlan(@RequestBody Plan plan,
                                 @RequestHeader("token") String token){
        return planService.deleteLogical(plan);
    }

}
